package com.finals.finalsscreen.app;

import android.annotation.TargetApi;
import android.app.Application;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;

import com.finals.finalsscreen.dialog.IncallDialog;
import com.finals.finalsscreen.service.SplashScreenService;

public class BaseApplication extends Application {

	Handler mHandler;

	FActivityLifecycleCallbacks mLifecycleCallbacks;

	@Override
	public void onCreate() {
		super.onCreate();
		InitCreash();
		StartService();
		RegisterActivityCallback();
	}

	private void InitCreash() {
		CrashHandler mCrashHandler = new CrashHandler();
		mCrashHandler.init(this);
	}

	private void StartService() {
		Intent intent = new Intent(this, SplashScreenService.class);
		startService(intent);
	}

	@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
	private void RegisterActivityCallback() {
		mHandler = new Handler(Looper.getMainLooper());
		if (android.os.Build.VERSION.SDK_INT >= 14) {
			mLifecycleCallbacks = new FActivityLifecycleCallbacks(this);
			this.registerActivityLifecycleCallbacks(mLifecycleCallbacks);
		}
	}

	IncallDialog mIncallDialog;

	public void showWindow() {
		if (mIncallDialog == null) {
			mIncallDialog = new IncallDialog(this);
		}
		mIncallDialog.show();
	}

	public void closeWindow() {
		if (mIncallDialog != null) {
			mIncallDialog.dismiss();
		}
	}

	public void stopOpenCallActivity() {

	}

}
